﻿using Kevin.Comm.Logger;
using Kevin.Shop.Business.SalesManagement.Components.Order;
using Kevin.Shop.Business.Service.Entity.Helper;
using Kevin.Shop.Business.Service.Entity.SalesManagement.Order;
using RiderShop.Mobile.Common.Component;
using RiderShop.Mobile.Modle.MyAccount;
using RiderShop.Mobile.Modle.Purchase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace RiderShop.Mobile.Controllers.Purchase
{
    public partial class PurchaseController : ThemeController
    {
        /// <summary>
        ///  修改鲜享卡 | 联名卡 |  银信商通卡密码
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public ActionResult YinxinModifyPassword()
        {
            return View(WebClientContext.Current.SiteTheme, "Purchase", "YinxinModifyPassword", WebClientContext.Current.CacheKeyDefaultMasterPage, null);
        }

        /// <summary>
        ///  修改鲜享卡 | 联名卡 |  银信商通卡密码
        /// </summary>
        /// <param name="cardNumber">卡号</param>
        /// <param name="oldPassword">老密码</param>
        /// <param name="newPassword">新密码</param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public JsonResult YinxinModifyPassword(string cardNumber, string oldPassword, string newPassword)
        {
            if (string.IsNullOrWhiteSpace(cardNumber))
            {
                return Json(new { Status = false, ErrorMessage = "请输入卡号" }, JsonRequestBehavior.AllowGet);
            }

            if (string.IsNullOrWhiteSpace(oldPassword))
            {
                return Json(new { Status = false, ErrorMessage = "请输入老密码" }, JsonRequestBehavior.AllowGet);
            }

            if (string.IsNullOrWhiteSpace(newPassword))
            {
                return Json(new { Status = false, ErrorMessage = "请输入新密码" }, JsonRequestBehavior.AllowGet);
            }

            cardNumber = cardNumber.Trim();
            oldPassword = oldPassword.Trim();
            newPassword = newPassword.Trim();
            try
            {
                var response = YinxinModel.ModifyYinxinPassword(cardNumber, oldPassword, newPassword);

                if (response.Status == true && string.IsNullOrEmpty(response.ErrorMessage))
                {
                    return Json(new { Status = true,ErrorMessage = ""}, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    return Json(new { Status = response.Status, ErrorMessage = response.ErrorMessage }, JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception ex)
            {
                Tracer.TraceLog("Modify YinxinCard Password Exception: " + ex.Message, "Modify YinxinCard Password", "ModifyYinxinCardPassword", true);

                return Json(new { Status = false, ErrorMessage = "服务器异常，请刷新页面重试！" }, JsonRequestBehavior.AllowGet);
            }
        }
    }
}
